import express from 'express';
import { addSql, getResult } from '../../../util/operateSql.js';
import { handleSendMessage } from '../../weixin/sendMessage.js';
import { generateOrderCode } from '../../../util/generalCode.js';
var router = express.Router()
const table = "activity_master.t_order"

router.post('/add',async (req,res,next) => {
  const {spu_id, merchant_id:shop_id, users_id:customer_id} = req.body
  const payload = {
    shop_id,customer_id,
    code: generateOrderCode(),
    type: 1,
    payment_type: 3,
    status: 1
  }
  const ordersql = addSql(table,payload)
  try {
    const rows = await getResult(ordersql)
    await handleSendMessage(req.body)
    res.json(req.app.locals.success('下单成功'))

  } catch (error) {
    console.log('error: ', error);
    res.json(req.app.locals.error(error))
  }
  

  // const orderDetailSql = addSql(detailPayload)
})

export default router